<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/mall/goods/brand/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='ppmc'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsrppmc'/>" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='zt'/></label>
                        <div class="layui-input-inline">
                            <select name="status" lay-verify="required" lay-search="">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <option value="2"
                                        <c:if test="${2 eq params.status}">selected="selected" </c:if> ><fmt:message key='dsh'/>
                                </option>
                                <option value="3"
                                        <c:if test="${3 eq params.status}">selected="selected" </c:if> ><fmt:message key='qy'/>
                                </option>
                                <option value="4"
                                        <c:if test="${4 eq params.status}">selected="selected" </c:if> ><fmt:message key='jy'/>
                                </option>
                            </select>

                        </div>
                    </div>


                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='tjpp'/></a>


            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li
                            <c:if test="${params.status eq 0}">class="layui-this"</c:if> >
                        <a href="${web_domain}/mall/goods/brand/list"
                           <c:if test="${params.status eq 0}">style="color: rgb(0, 150, 136)"</c:if> ><fmt:message key='qb'/></a>
                    </li>

                </ul>
            </div>


            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th width="5%"><fmt:message key='xh'/></th>
                    <th width="15%"><fmt:message key='ppmc'/></th>
                    <th width="15%"><fmt:message key='pplogo'/></th>
                    <th width="10%"><fmt:message key='ppms'/></th>
                    <th><fmt:message key='tjsy'/></th>
                    <th><fmt:message key='cjsj'/></th>
                    <th width="10%"><fmt:message key='zt'/></th>
                    <th width="10%"><fmt:message key='cz'/></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td>${status.index + 1}</td>
                        <td>${item.name }</td>
                        <td><img src="${store_domain}/uploads/${item.logo }" class="preview" style="width:40px;height:40px;"/></td>
                        <td>${item.note }</td>
                        <td>
                            <input type="checkbox" name="recommend" lay-filter="recommend" data-id="${item.id}" lay-skin="switch" lay-text="<fmt:message key='s|f'/>" <c:if test="${item.recommend}">checked</c:if>>
                        </td>
                        <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status eq 2}"><fmt:message key='dsh'/></c:when>
                                <c:when test="${item.status eq 3}"><fmt:message key='qy'/></c:when>
                                <c:when test="${item.status eq 4}"><fmt:message key='jy'/></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">

                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj'/></a>
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc'/></a>

                                <c:choose>
                                    <c:when test="${item.status eq 2}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-enabled"><fmt:message key='qy'/></a>
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-disabled"><fmt:message key='jy'/></a>
                                    </c:when>
                                    <c:when test="${item.status eq 3}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-disabled"><fmt:message key='jy'/></a>
                                    </c:when>
                                    <c:when test="${item.status eq 4}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-enabled"><fmt:message key='qy'/></a>
                                    </c:when>
                                </c:choose>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    layui.use(['form', 'laydate'], function () {

        var form = layui.form;
        var laydate = layui.laydate;
        form.on('switch(recommend)', function (data) {
            var checked = data.elem.checked;
            var id = $(data.elem).attr("data-id");

            feijin.put({
                url: "${web_domain}/mall/goods/brand/recommend",
                data: {"id": id, "recommend": checked},
                success: function (result) {
                    if (result.status) {
                        layer.msg("<fmt:message key='cg'/>");
                    }
                }
            });


        });
    });

    $(function () {

        $(".feijin-enabled").click(function () {
            var id = $(this).attr("data-id");

            feijin.put({
                url: "${web_domain}/mall/goods/brand/enabled",
                data: {"id": id},
                success: function (result) {
                    if (result.status) {
                        layer.msg("<fmt:message key='cg'/>");
                        location.reload();
                    }
                }
            });
        });

        $(".feijin-disabled").click(function () {
            var id = $(this).attr("data-id");

            feijin.put({
                url: "${web_domain}/mall/goods/brand/disabled",
                data: {"id": id},
                success: function (result) {
                    if (result.status) {
                        layer.msg("<fmt:message key='cg'/>");
                        location.reload();
                    }
                }
            });
        });

        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjpp'/>'
                , content: '${web_domain}/mall/goods/brand/create'
                , maxmin: true
                , area: ['80%', '80%']
                , btn: ['<fmt:message key='qd1'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //编辑
        $(".feijin-modify").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjpp'/>'
                , content: '${web_domain}/mall/goods/brand/' + id + '/modify'
                , maxmin: true
                , area: ['80%', '80%']
                , btn: ['<fmt:message key='qd1'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });


        //删除品牌
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='scpp'/>',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='sccz,qdscgppm?'/></span>',
                    btn: ['<fmt:message key='sc'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/mall/goods/brand/remove",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "delete"
                            },
                            success: function (data) {
                                if (data.status) {
                                    location.reload();
                                } else {
                                    layui.use('layer', function () {
                                        layer.msg(data.message);
                                    });
                                }

                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });


    });
</script>
</body>
</fmt:bundle>
</html>
